import api from '../../http/api'
//全局变量
const app = getApp();
Page({
    data: {
        isSubmit:false,
        drug_list:[],
        drug_list2:[],
        ill_textarea_mess:[],
        comeback:false,
        address_text:'请选择收货地址',
        drug_price:0,
        drug_shopName:'',
    },
    selection(e){
        // console.log(e.currentTarget.dataset.name);
        this.setData({
            drug_shopName:''
        })
        // this.data.drug_detailMessage.push(this)
        this.data.ill_textarea_mess.push(e.currentTarget.dataset.item.name)
        this.data.drug_price += e.currentTarget.dataset.item.price
        this.data.drug_shopName = e.currentTarget.dataset.item.shop_name
        this.setData({
            ill_textarea_mess: this.data.ill_textarea_mess,
            drug_price:this.data.drug_price,
            drug_shopName:this.data.drug_shopName
        })
    },
    formSubmit(e) {
        // console.log('form发生了submit事件，携带数据为：', e.detail.value);
        let item =e.detail.value
        let timeDate =  new Date()
        let month  =  timeDate.getMonth()+1
        let DateValue =  timeDate.getFullYear()+'年'+month+'月'+timeDate.getDate()+'日'+timeDate.getHours()+'时'+timeDate.getMinutes()+'分'

        let AppAddress = app.globalData.current_address
        console.log('傻逼username',item.username);
            //插入数据到数据库
        console.log(AppAddress.username);
         api.postData('/order_lists/insert?doctor='
         +item.doctor+"&date="+DateValue+"&username="+item.username+"&age="+item.age+"&sex="+item.sex+"&IDcard="+item.IDcard+'&ill_history='+item.ill_history+'&result='+item.result+'&need_detail='+item.need_detail+'&address='+AppAddress.username+","+AppAddress.phone+","+AppAddress.city+AppAddress.town+AppAddress.detail_address+'&help='+item.help+'&total_price='+this.data.drug_price+'&source='+this.data.drug_shopName+'&num='+app.globalData.current_address_num+'&shop_names='+app.globalData.shop_names)
         //跳转回shop去
         wx.navigateBack({
             data:1
         }) 
         app.globalData.refresh_shop = true
      },
      //跳转回shop去
      cancel(){
        wx.navigateBack({
            data:1
        }) 
      },
      gotoaddress(){
        app.globalData.parameter = 2
        wx.navigateTo({
          url: '../my_address/my_address',
        })
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
			api.getData('/good1s').then(res => {
                    this.setData({
                        drug_list:res.params.data
                    })
            })
            api.getData('/good2s').then(res => {
                    this.setData({
                        drug_list2:res.params.data
                    })
            })
            if(app.globalData.comeback==true){
                this.setData({
                    comeback:true
                })
                console.log( app.globalData.current_address);
                this.setData({
                    address_text:'-----------当前地址'+app.globalData.current_address_num+'-------------'
                })
            }
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})